//
//  SortJumpViewController.m
//  GetPowerDBO
//
//  Created by 周博 on 2017/7/14.
//  Copyright © 2017年 BogoZhou. All rights reserved.
//

#import "SortJumpViewController.h"
#import "BorderHelper.h"

@interface SortJumpViewController ()
{
}

@property (nonatomic,assign) BOOL defaultValue;
@property (nonatomic,assign) BOOL online;

@property (nonatomic,assign) NSInteger zaixian;
@property (nonatomic,assign) NSInteger dianliang;
@property (nonatomic,assign) NSInteger antian;
@property (nonatomic,assign) NSInteger leixing;

@end

@implementation SortJumpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self UISetting];
}

#pragma mark - 设置页面

- (void)UISetting{
    
    _layoutWidth.constant = kScreenSize.width;
    _layoutHeight.constant = 530;
    _backGroundButton.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
    
    [self set101];
    [self set201];
    [self set301];
    [self set401];
    [self set501];
    
    _defaultValue = _defaultValueNUM.boolValue;
    
    [self setDefaultFuncByBool:_defaultValue];
    
    _zaixian = _zaixianNUM.integerValue;
    _dianliang = _dianliangNUM.integerValue;
    _antian = _antianNUM.integerValue;
    _leixing = _leixingNUM.integerValue;
    
    if (_defaultValue == NO) {
        if (_zaixian > 0) {
            UIButton *button = (UIButton *)[self.view viewWithTag:_zaixian];
            [self chooseButtonTypeWithButton:button];
        }
        if (_dianliang > 0) {
            UIButton *button2 = (UIButton *)[self.view viewWithTag:_dianliang];
            [self chooseButtonTypeWithButton:button2];
        }
        
        if (_antian) {
            UIButton *button3 = (UIButton *)[self.view viewWithTag:_antian];
            [self chooseButtonTypeWithButton:button3];
        }
        
        if (_leixing) {
            UIButton *button4 = (UIButton *)[self.view viewWithTag:_leixing];
            [self chooseButtonTypeWithButton:button4];
        }
    }
}


- (void)set101{
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonZaixianZaixian];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonZaixianLixian];
    _zaixian = 0;
}

- (void)set201{
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonPowerGD];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonPowerDG];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button80];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button60];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button40];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button20];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button0];
    _dianliang = 0;
}

- (void)set301{
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button3Days];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button5Days];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_button7Days];
    _antian = 0;
}

- (void)set401{
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonCancel];
    _buttonSure.backgroundColor = kGreenColor;
}

- (void)set501{
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonWIfi];
    [BorderHelper setBorderWithColor:ke6e6e6 view:_buttonMima];
    _leixing = 0;
}

- (void)chooseButtonTypeWithButton:(UIButton *)button{
    button.layer.borderColor = [kGreenColor CGColor];
    button.layer.borderWidth = 0.5f;
    [button setTitleColor:kGreenColor forState:UIControlStateNormal];
    button.backgroundColor = [kGreenColor colorWithAlphaComponent:0.2];
}
#pragma mark - 点击事件

//点击默认
- (IBAction)buttonMoRenButtonClick:(UIButton *)sender {
    [self setDefaultFuncByBool:YES];
    [self set101];
    [self set201];
    [self set301];
    [self set401];
    [self set501];
}


/**
 在线排序

 @param sender 100 只看在线 ; 101 只看离线
 */
- (IBAction)zaixianButtonClick:(UIButton *)sender {
    [self setDefaultFuncByBool:NO];
    if (sender.tag == 102) {
        [self set301];
    }
    [self set101];
    _zaixian = sender.tag;
    [self chooseButtonTypeWithButton:sender];
}


/**
 电量排序

 @param sender 207 电量从高到底 ； 206 电量从低到高 ； 205 80以上 ；204 60 ； 203 40 ； 202 20 ； 201 0；
 */
- (IBAction)dianliangButtonClick:(UIButton *)sender {
    [self setDefaultFuncByBool:NO];
    [self set201];
    _dianliang = sender.tag;
    [self chooseButtonTypeWithButton:sender];
}



/**
 按天数排序

 @param sender 303 3天 ; 305 5天 ； 307 7天
 */
- (IBAction)tianshuButtonClick:(UIButton *)sender {
    [self setDefaultFuncByBool:NO];
    if (_zaixian != 101) {
        [self set101];
        _zaixian = 101;
        [self zaixianButtonClick:_buttonZaixianLixian];
    }
    
    [self set301];
    _antian = sender.tag;
    [self chooseButtonTypeWithButton:sender];
}


/**
 按类型排序
 501 -> WiFi ； 502 -> 密码
 */
- (IBAction)typeButtonClick:(UIButton *)sender {
    [self setDefaultFuncByBool:NO];
    [self set501];
    _leixing = sender.tag;
    [self chooseButtonTypeWithButton:sender];
}


//cancel
- (IBAction)cancelButtonClick:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//sure
- (IBAction)sureButtonClick:(UIButton *)sender {
    [_delegate getSortJumpInfoWithDefault:[NSNumber numberWithBool:_defaultValue] zaixian:[NSNumber numberWithInteger:_zaixian] dianliang:[NSNumber numberWithInteger:_dianliang] antian:[NSNumber numberWithInteger:_antian] leixing:[NSNumber numberWithInteger:_leixing]];
    [self dismissViewControllerAnimated:YES completion:nil];
}



- (void)setDefaultFuncByBool:(BOOL)def{
    _defaultValue = def;
    _imageViewMoren.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",_defaultValue ? @"xuanzhonglv" : @"xuanzhonghui"]];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
